{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>资产分配</title>
  <link href="{% static 'vendor/bootstrap/bootstrap.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/fontawesome/all.min.css' %}" rel="stylesheet">
</head>
<body class="p-3">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12 col-lg-8">
        <h5 class="mb-3">资产分配</h5>
        <div class="card mb-3">
          <div class="card-header"><strong>{{ asset.name }}</strong></div>
          <div class="card-body">
            <div class="row g-2 small text-muted">
              <div class="col-6">资产编号：{{ asset.asset_number }}</div>
              <div class="col-6">所属部门：{{ asset.department.name|default:'-' }}</div>
              <div class="col-6">使用人：{% if asset.user %}{{ asset.user.username }}{% else %}-{% endif %}</div>
              <div class="col-6">当前状态：
                {% if asset.status == 'idle' %}<span class="badge bg-secondary">闲置</span>
                {% elif asset.status == 'in_use' %}<span class="badge bg-success">在用</span>
                {% elif asset.status == 'maintenance' %}<span class="badge bg-warning">维修中</span>
                {% elif asset.status == 'scrapped' %}<span class="badge bg-danger">已报废</span>
                {% endif %}
              </div>
            </div>
          </div>
        </div>

        <form method="post">
          {% csrf_token %}
          <input type="hidden" name="modal" value="1">
          <div class="mb-3">
            <label for="department" class="form-label">分配到部门</label>
            <select class="form-select" id="department" name="department">
              <option value="">请选择部门</option>
              {% for department in departments %}
              <option value="{{ department.id }}" {% if asset.department_id == department.id %}selected{% endif %}>{{ department.name }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="mb-3">
            <label for="user" class="form-label">分配给用户</label>
            <select class="form-select" id="user" name="user">
              <option value="">请选择用户</option>
              {% for user in users %}
              <option value="{{ user.id }}" {% if asset.user_id == user.id %}selected{% endif %}>{{ user.username }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="mb-3">
            <label for="description" class="form-label">备注</label>
            <textarea class="form-control" id="description" name="description" rows="3"></textarea>
          </div>
          <div class="d-flex gap-2">
            <button type="submit" class="btn btn-primary">确认分配</button>
            <button type="button" class="btn btn-outline-secondary" onclick="window.history.back()">返回</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</body>
</html>
